//
//  Statues.swift
//  swiftImitationWeibo
//
//  Created by 杨果果 on 16/7/13.
//  Copyright © 2016年 yang. All rights reserved.
//

import UIKit

class Statues: NSObject {
    var created_at: String?
    var id: Int64 = 0
    var text: String?
    var source: String?
    var user: User?
    var reposts_count: Int = 0
    var comments_count: Int = 0
    var attitudes_count: Int = 0
    //转发微博对象
    var retweeted_status: Statues?
    
    //配图
    var pic_urls: [StatusPictureInfo]?
    
    
    
    init(dic:[String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    //执行上面遍历实际是取用setvalue forkey
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            user = User(dic: dic)
  
        } else if key == "retweeted_status" {
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            retweeted_status = Statues(dic: dic)
        } else if key  == "pic_urls"{
            guard let dicArray = value as? [[String: AnyObject]] else {
                return
            }
            var tempArray = [StatusPictureInfo]()
            for dic in dicArray {
                let pictureInfo = StatusPictureInfo(dic: dic)
                tempArray.append(pictureInfo)
            }
            pic_urls = tempArray
        } else {
            super.setValue(value, forKey: key)
        }
        
    }
    
    
    
    
    
    
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}

